package com.qianlima.upload.common.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @description: 全局统一的JSON返回值
 * @author：allms
 * @date: 2023/3/21 14:42
 */
@Data
@AllArgsConstructor
public class ResponseDto<T> {
    /**
     * 业务上的成功或失败
     */
    private boolean success;

    /**
     * 返回码
     */
    private String code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回泛型数据，自定义类型
     */
    private T content;


    public static ResponseDto<Object> success(Object content) {
        return new ResponseDto<>(true, "200", "请求成功", content);
    }

    public static ResponseDto success() {
        return success(null);
    }

    public static ResponseDto fail() {
        return new ResponseDto(true, "500", "服务器内部出错了", null);
    }

    public static ResponseDto fail(String cause) {
        return new ResponseDto(true, "500", "服务器内部出错了", cause);
    }

}
